package com.tongji.housediy.view
{
	import com.tongji.housediy.events.commonEvent.ListItemMouseEvent;
	import com.tongji.housediy.events.commonEvent.RoomNameAdminEvent;
	import com.tongji.housediy.events.commonEvent.ShowHideTitleWindowEvent;
	import com.tongji.housediy.model.BrandModel;
	import com.tongji.housediy.model.CompEnableStateModel;
	import com.tongji.housediy.utils.DragDropManager;
	import com.tongji.housediy.view.components.CommonWindow;
	import com.tongji.housediy.view.components.DoubleDoor;
	import com.tongji.housediy.view.components.DoubleShiftDoor;
	import com.tongji.housediy.view.components.DoubleWindow;
	import com.tongji.housediy.view.components.FixedWindow;
	import com.tongji.housediy.view.components.Furniture;
	import com.tongji.housediy.view.components.ShiftDoor;
	import com.tongji.housediy.view.components.SingleDoor;
	
	import flash.events.MouseEvent;
	
	import mx.binding.utils.BindingUtils;
	import mx.controls.Alert;
	
	import org.robotlegs.mvcs.Mediator;
	
	public class BrandDetailMediator extends Mediator
	{
		[Inject]
		public var view:BrandDetail;
		
		[Inject]
		public var enableModel:CompEnableStateModel;
		
		[Inject]
		public var brandModel:BrandModel;
		
		override public function onRegister():void
		{
			view.backBtn.addEventListener(MouseEvent.CLICK, backToMainHandler);
			view.goodsTotal.text = "该品牌共" + brandModel.total + "个产品";
			BindingUtils.bindProperty(view.goodsList.bigList.dataGroup, "dataProvider", brandModel, "goodsList");
			view.addEventListener(ListItemMouseEvent.ITEM_MOUSE_DOWN, listMouseDownHandler);
		}
		
		private function listMouseDownHandler(event:ListItemMouseEvent):void
		{
			//dispatch(new ShowHideTitleWindowEvent(ShowHideTitleWindowEvent.HIDE_TITLE_WINDOW));
			//dispatch(new RoomNameAdminEvent(RoomNameAdminEvent.HIDE_ROOM_NAME));
			
			switch (event.hostType)
			{
				case "doorFormat":
					if (event.target.data.typeTag == "singleDoor")
					{
						DragDropManager.startDragBorderChild(view, event.myEvent, event.hostType,
							new SingleDoor(event.content.width, event.content, event.target.data));
					}
					else if (event.target.data.typeTag == "doubleDoor")
					{
						DragDropManager.startDragBorderChild(view, event.myEvent, event.hostType,
							new DoubleDoor(event.content.width, event.content, event.target.data));
					}
					else if (event.target.data.typeTag == "shiftDoor")
					{
						DragDropManager.startDragBorderChild(view, event.myEvent, event.hostType,
							new ShiftDoor(event.content.width, event.content, event.target.data));
					}
					else if (event.target.data.typeTag == "doubleShiftDoor")
					{
						DragDropManager.startDragBorderChild(view, event.myEvent, event.hostType,
							new DoubleShiftDoor(event.content.width, event.content, event.target.data));
					}		
					break;
				case "windowFormat":
					if (event.target.data.typeTag == "commonWindow")
					{
						DragDropManager.startDragBorderChild(view, event.myEvent, event.hostType,
							new CommonWindow(event.content.width, event.content, event.target.data));
					}
					if (event.target.data.typeTag == "fixedWindow")
					{
						DragDropManager.startDragBorderChild(view, event.myEvent, event.hostType,
							new FixedWindow(event.content.width, event.content, event.target.data));
					}
					if (event.target.data.typeTag == "doubleWindow")
					{
						DragDropManager.startDragBorderChild(view, event.myEvent, event.hostType,
							new DoubleWindow(event.content.width, event.content, event.target.data));
					}
					break;
				case "furnitureFormat":
					DragDropManager.startDragFurniture(view, event.myEvent, new Furniture(event.target.data, event.content));
					break;
				case "mapFormat":
					DragDropManager.startDragFloorMap(view, event.myEvent, event.content, event.target.data);
					break;
			}
		}
		private function backToMainHandler(event:MouseEvent):void
		{
			enableModel.stateIndex = 0;
		}
	}
}